// @algorithm @lc id=443 lang=cpp 
// @title string-compression

// #define print(...)
class Solution {
public:
    int compress(vector<char>& chars) {
        auto n = chars.begin();
        for(auto f=chars.begin(), t=f; f!=chars.end(); f=t){
            *n++ = *f;
            while(t!=chars.end() && *t==*f)
                t++;
            if(t-f>1)
                for(auto i:to_string(t-f))
                    *n++ = i;
        }
        return n - chars.begin();
    }
};